﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using EventosTdd.Core.Entities;
using EventosTdd.Core.Services;

namespace EventosTdd.Web.Controllers
{
    public class EventoController : Controller
    {
        private EventoServices Servicio; 
        private ICantidadInscriptos CantidadInscriptos;


        public EventoController()
            : this(Dominio.Actual.Eventos, new CantidadInscriptos())
        {
        }

        public EventoController(IList<Evento> ListaEventos)
            :this(new EventoServices(ListaEventos))
        {
        }

        public EventoController(EventoServices Servicio)
        {
            this.Servicio = Servicio;
        }

        public EventoController(IList<Evento> ListaEventos, ICantidadInscriptos CantidadInscriptos)
        {
            this.Servicio = new EventoServices(ListaEventos);
            this.CantidadInscriptos = CantidadInscriptos;
        }


        public ActionResult Index()
        {
            return View(this.Servicio.GetEventos());
        }


        public ActionResult Create()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Create(Evento EventoCreado)
        {
            this.Servicio.AddEvento(EventoCreado);
            return RedirectToAction("Index");
        }

        public ActionResult Details(int Id)
        {
            var Model = this.Servicio.GetEventos().Where(e => e.Id == Id).FirstOrDefault();
            Model.CantidadInscriptos = this.CantidadInscriptos.GetCantidadInscriptos(Id);
            return View(Model);
        }

        public ActionResult Delete(int Id)
        {
            var Model = this.Servicio.GetEventos().Where(e => e.Id == Id).FirstOrDefault();
            return View(Model);
        }

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int Id)
        {
            this.Servicio.DeleteEvento(Id);
            return RedirectToAction("Index");
        }

        public ActionResult Edit(int Id)
        {
            var Model = this.Servicio.GetEventos().Where(e => e.Id == Id).FirstOrDefault();
            return View(Model);
        }

        [HttpPost]
        public ActionResult Edit(Evento Evento)
        {
            this.Servicio.EditEvento(Evento);
            return RedirectToAction("Index");
        }
    }
}

